#include "FileTools.h"


bool GetShortFilename(CString FullName, CString &ShortName)
	{
	WIN32_FIND_DATA Data;
	HANDLE Hand;

	int Pos, i;

	Pos = 0;
	ShortName.Empty();

	while (Pos < FullName.GetLength())
		{
		i = FullName.Mid(Pos).Find('\\');
		if (i < 0)
			Pos = FullName.GetLength();
		else
			Pos += i + 1;

#ifdef _DEBUG
		CString FindName = FullName.Left(Pos);
#endif
		if ((Hand = FindFirstFile(FullName.Left(Pos), &Data)) == INVALID_HANDLE_VALUE &&
			(Hand = FindFirstFile(FullName.Left(Pos) + ".", &Data)) == INVALID_HANDLE_VALUE)
			ShortName = FullName.Left(Pos);
		else
			{
			if (Data.cAlternateFileName[0] > '\0')
				ShortName += Data.cAlternateFileName;
			else
				ShortName += Data.cFileName;
			if (FullName[Pos-1] == '\\')
				ShortName += '\\';
			FindClose(Hand);
			}
		}

	return true;
	}

